//
//  ChatViewController.m
//  IOSTest
//
//  Created by Afluy on 14/12/28.
//  Copyright (c) 2014年 Afluy. All rights reserved.
//学习链接：http://blog.csdn.net/qq5306546/article/details/8062606

#import "ChatViewController.h"

@interface ChatViewController (){
    //成员变量定义在头文件中,@protected(作用范围在自身类和继承自己的子类，什么都不写，默认是此属性)
    //成员变量定义在源文件，则变量的访问权限都为@private(作用范围只能在自身类)
    UITableView *mTableView;
    NSMutableArray *mChats;
}
@end



@implementation ChatViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    
    //UIImage *iconImg = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource: @"icon" ofType:@"png"]];
    UIImage *iconImg =[UIImage imageNamed:@"icon"];
    mChats = [[NSMutableArray alloc]initWithCapacity:20];
    for(int i=0;i<10;++i){
        SessionData *data1=[[SessionData alloc]init];
        data1.fromSelf = NO;
        data1.icon = iconImg;
        data1.content=@"你好....................................";
        data1.date= nil;
        
        SessionData *data2=[[SessionData alloc]init];
        data2.fromSelf = YES;
        data2.icon = iconImg;
        data2.content=@"最近怎么样......................................";
        data2.date= nil;
    
        
        [mChats addObject:data1];
        [mChats addObject:data2];
    }
    

  
    
    mTableView =[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 420)];
    [mTableView setDelegate:self];
    [mTableView setDataSource:self];
    [self.view addSubview:mTableView];
    
}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 10;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
//绘制Cell
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellID = @"Cell";
    
    UITableViewCell *cell =(UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellID];
    if(cell==nil){
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:CellID];
    }
    [cell.textLabel setText:@"0"];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"点击了%d",indexPath.section);
    
    ChatingViewController *chatingVC=[[ChatingViewController alloc]init];
    [chatingVC setHidesBottomBarWhenPushed:YES];
    chatingVC.title = @"0";
    
    [chatingVC refreshData:mChats];
    
    [self.navigationController pushViewController:chatingVC animated:true];
    
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"执行删除操作");
}
-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{
     NSLog(@"执行删除操作from %d to %d ",sourceIndexPath.section, destinationIndexPath.section);
}
@end
